home *** CD-ROM | disk | FTP | other *** search
- Path: news3.noc.netcom.net!silvaco!spock!mikep
- From: mikep@Silvaco.COM (Mike Potts)
- Newsgroups: comp.lang.c++
- Subject: Q: how to store class member function pointers in class B
- Date: 27 Feb 1996 17:02:10 GMT
- Organization: Silvaco Data Systems, Inc, Santa Clara, CA
- Message-ID: <4gvdei$rra@news.Silvaco.COM>
- X-Newsreader: TIN [version 1.2 PL2]
-
- This is a dumb question from a relative newbie: can I store a pointer to
- a member function of one class in another class? Specifically, in a gui
- application, I want to construct a button class which stores a pointer
- to a callback in its parent. I'm currently trying something like:
-
- class Button : public ProtoButton {
- void (Panel::*function)(void);
-
- void inheritedCallback(void) {
- this->*function();
- }
-
- Button((Panel::*func)(void)) {
- function = func;
- }
- }
-
- class Panel : public protoPanel {
- friend class Button;
-
- void buttonCallback(void) {...}
-
- Panel(void) {
- new Button(buttonCallback);
- }
- }
-
- but I get compile-time errors along the lines that there's a problem making
- a cast from (Button) this to (Panel) this, which I completely fail to make
- head nor tail of. If this doesn't make any sense I apologise; if there's a
- sensible way to do this I'd be grateful if someone could enlighten me!
-
- Thanks
-
- Mike
-
-